package com.ruoyi.chat.util;


import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.ruoyi.chat.domain.ChatMessage;
import org.springframework.stereotype.Component;

import javax.websocket.DecodeException;
import javax.websocket.Decoder;
import javax.websocket.EndpointConfig;


public class ChatMessageDecoder implements Decoder.Text<ChatMessage>{
    @Override
    public ChatMessage decode(String s) throws DecodeException {
        System.out.println("decoding");
        return new GsonBuilder()
                .setDateFormat("yyyy-MM-dd HH:mm:ss")
                .create()
                .fromJson(s, ChatMessage.class);
    }

    @Override
    public boolean willDecode(String s) {
        return true;
    }

    @Override
    public void init(EndpointConfig endpointConfig) {
    }

    @Override
    public void destroy() {

    }
}
